﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml.Linq;
using System.Collections.Generic;
namespace CricketHub
{
    public partial class Schedule1 : PhoneApplicationPage
    {
        Schedule_web sch_web = new Schedule_web();
        public Schedule1()
        {
            
            InitializeComponent();
            sch_web.schd = this;
            sch_web.schedule_teams();
            schedulepg.Visibility = Visibility.Visible;
            
        }
        List<Schedule_data> schedule_list = new System.Collections.Generic.List<Schedule_data>();
        ListBox list_items = new ListBox();
        public void Scudule_data(string teams)
        {
            var element = XElement.Parse(teams);
            var root_element = element.Descendants("mch").Count();
            System.Diagnostics.Debug.WriteLine(root_element);
            for (int index = 0; index < root_element; index++)
            {
                var data = element.Descendants("mch").ElementAt(index);
                Schedule_data obj = new Schedule_data();
                obj.mnt_yr = data.Attribute("mnth_yr").Value;
                obj.tm = data.Attribute("tm").Value;
                obj.venu = data.Attribute("vnu").Value;
                obj.ddt = data.Attribute("ddt").Value;
                obj.srs = data.Attribute("srs").Value;
                obj.desc = data.Attribute("desc").Value;
                schedule_list.Add(obj);
               // Deployment.Current.Dispatcher.BeginInvoke(() =>
                  //  {
                     /*   StackPanel stk = new StackPanel();
                        stk.Height = 150;
                        TextBlock srs = new TextBlock();
                        srs.Text = data.Attribute("srs").Value;
                        srs.FontSize = 26;
                        srs.HorizontalAlignment = HorizontalAlignment.Center;
                        TextBlock desc = new TextBlock();
                        desc.Text = data.Attribute("desc").Value;
                        desc.FontSize = 22;
                        desc.HorizontalAlignment = HorizontalAlignment.Center;
                        TextBlock venu = new TextBlock();
                        venu.Text = data.Attribute("vnu").Value;
                        venu.TextWrapping = TextWrapping.Wrap;
                        venu.FontSize = 22;
                        venu.HorizontalAlignment = HorizontalAlignment.Left;
                        TextBlock ddt = new TextBlock();
                        ddt.FontSize = 22;
                        ddt.Text = data.Attribute("ddt").Value;
                        ddt.HorizontalAlignment = HorizontalAlignment.Right;
                        ddt.Margin = new Thickness(0, -30, 0, 0);
                        TextBlock tm = new TextBlock();
                        tm.FontSize = 22;
                        tm.Text = data.Attribute("tm").Value;
                        tm.HorizontalAlignment = HorizontalAlignment.Right;
                        stk.Children.Add(srs);
                        stk.Children.Add(desc);
                        stk.Children.Add(venu);
                        stk.Children.Add(ddt);
                        stk.Children.Add(tm);
                        list_items.Items.Add(stk); */
                   // });
 
            }

            Deployment.Current.Dispatcher.BeginInvoke((CreateListBox));


 
        }

        private void CreateListBox()
        {
            CreateList();
            load_List();
            schedulepg.Visibility = Visibility.Collapsed;

        }
        ListBox newsList;//= new ListBox();
        private void CreateList()
        {
            newsList = new ListBox();
            newsList.Name = "listbox";
            newsList.Height = 630;
            newsList.Width = 450;
            newsList.VerticalAlignment = VerticalAlignment.Top;
            newsList.Background = new SolidColorBrush(Colors.Transparent);
            ContentPanel.Children.Add(newsList);




        }

        public void load_List()
        {
            for (int index = 0; index < schedule_list.Count; index++)
            {
                StackPanel stk = new StackPanel();
                stk.Height = 160;
                TextBlock srs = new TextBlock();
                srs.Text = schedule_list.ElementAt(index).srs;//data.Attribute("srs").Value;
                srs.FontSize = 26;
                srs.Foreground = new SolidColorBrush(Colors.Black);
                srs.FontWeight = FontWeights.Bold;
                srs.HorizontalAlignment = HorizontalAlignment.Center;
                TextBlock desc = new TextBlock();
                desc.Text = schedule_list.ElementAt(index).desc;//data.Attribute("desc").Value;
                desc.FontSize = 22;
                desc.HorizontalAlignment = HorizontalAlignment.Center;
                desc.Foreground = new SolidColorBrush(Colors.Blue);
                desc.FontWeight = FontWeights.Bold;
                TextBlock venu = new TextBlock();
                venu.Text = schedule_list.ElementAt(index).venu;//data.Attribute("vnu").Value;
                venu.TextWrapping = TextWrapping.Wrap;
                venu.Foreground = new SolidColorBrush(Colors.Brown);
                venu.FontSize = 22;
                venu.HorizontalAlignment = HorizontalAlignment.Left;
                TextBlock ddt = new TextBlock();
                ddt.FontSize = 22;
                ddt.Foreground = new SolidColorBrush(Colors.Black);
                ddt.FontWeight = FontWeights.SemiBold;
                ddt.Text = schedule_list.ElementAt(index).mnt_yr +"  "+schedule_list.ElementAt(index).ddt;//data.Attribute("ddt").Value;
                ddt.HorizontalAlignment = HorizontalAlignment.Right;
                ddt.Margin = new Thickness(0, -10, 0, 0);
                TextBlock tm = new TextBlock();
                tm.FontSize = 22;
                tm.FontWeight = FontWeights.SemiBold;
                tm.Foreground = new SolidColorBrush(Colors.Black);
                tm.Text = schedule_list.ElementAt(index).tm;//data.Attribute("tm").Value;
                tm.HorizontalAlignment = HorizontalAlignment.Right;
                Line l1 = new Line();
                l1.Stroke = new SolidColorBrush(Colors.Green);
                l1.StrokeThickness = 7;
                l1.X1 = 0;
                l1.X2 = 500;
                l1.Y1 = 0;
                l1.Y2 = 0;
                stk.Children.Add(srs);
                stk.Children.Add(desc);
                stk.Children.Add(venu);
                stk.Children.Add(ddt);
                stk.Children.Add(tm);
                stk.Children.Add(l1);
                //list_items.Height = 600;
                //list_items.Width = 450;
                newsList.Items.Add(stk);
                
            }
           // ContentPanel.Children.Add(list_items);
 
        }
        
    }
}